﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using SERP.StringMappings;
using SERP.DAO;
using SERP.Controllers;
namespace SERP.Modules.Menus{
	public partial class MenusInputFields : SERP.Modules.ModuleBase
	{
		protected void Page_Load(object sender, EventArgs e){
			LoadLanguage();
		}
		private MenusEntity model=new MenusEntity();
		public MenusEntity Model{
			set{
				model=value;
			}
			get{
				return model;
			}
		}
		//Load All lable text
		private void LoadLanguage(){
			labelMenuName.Text=MenusStringMapping.MenuName+":";
			labelDescription.Text=MenusStringMapping.Description+":";
			labelIconName.Text=MenusStringMapping.IconName+":";
			labelMenuUrl.Text=MenusStringMapping.MenuUrl+":";
			labelParentId.Text=MenusStringMapping.ParentId+":";
			validRQParentId.ErrorMessage=SERP.Constants.APP_REQUIRE_WARNING;
			labelModuleId.Text=MenusStringMapping.ModuleId+":";
			validRQModuleId.ErrorMessage=SERP.Constants.APP_REQUIRE_WARNING;
		}   
		public void UpdateToModel(){
			model.MenuName=Convert.ToString(txtMenuName.Text);
			model.Description=Convert.ToString(txtDescription.Text);
			model.IconName=Convert.ToString(txtIconName.Text);
			model.MenuUrl=Convert.ToString(txtMenuUrl.Text);
			model.ParentId=Convert.ToInt32(txtParentId.SelectedValue);
			model.ModuleId=Convert.ToInt32(txtModuleId.SelectedValue);
		}
		public void UpdateToScreen(){
			txtMenuName.Text=model.MenuName;
			txtDescription.Text=model.Description;
			txtIconName.Text=model.IconName;
			txtMenuUrl.Text=model.MenuUrl;
			txtParentId.SelectedValue=model.ParentId.ToString();
			txtModuleId.SelectedValue=model.ModuleId.ToString();
		}
		public void ClearScreen(){
			txtMenuName.Text="";
			txtDescription.Text="";
			txtIconName.Text="";
			txtMenuUrl.Text="";
		}
		public bool ValidateScreen(){
			bool result=true;
			if(txtParentId.SelectedIndex<=0){
				result=false;
				validRQParentId.IsValid=false;
			}
			else{
				validRQParentId.IsValid=true;
			}
			if(txtModuleId.SelectedIndex<=0){
				result=false;
				validRQModuleId.IsValid=false;
			}
			else{
				validRQModuleId.IsValid=true;
			}
			return result;
		}	
	}
}
